@extends('admin/layout')

@section('content')
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">商品管理</a></li>
                <li><a href="#">商品列表</a></li>
                <li class="active">修改商品信息</li>
            </ol>
        </section>
        <section class="content">
            <div class="row">
                <!-- left column -->
                <div class="col-md-12" style="width: 100%;">
                    <!-- general form elements -->
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <h3 class="box-title"></h3>
                        </div>
                        <!-- /.box-header -->
                        <span id="msg" style="display: none">
                            @if (count($errors) > 0)
                                @foreach ($errors->all() as $error)
                                    <div style="width: 100%;">
                                        <span style="color: red;display: block;margin: 0px auto;width: 200px;text-align: center;">{{ $error }}</span>
                                    </div>
                                @endforeach
                            @endif
                        </span>
                        <script type="text/javascript">
                            var _msg = $('#msg div span').text();
                            console.log(_msg);
                            if(_msg != ''){
                                layer.msg(_msg);
                            }
                        </script>
                        <form action="{{ url('admin/goods/updateGoods') }}" method="post" enctype="multipart/form-data">
                            {{ csrf_field() }}
                            <input type="hidden" name="id" value="{{ $list['id'] }}">
                            <div class="box-body" style="width: 50%;">
                                <div class="form-group">
                                    <label for="exampleInputName">商品名称</label>
                                    <input type="text" name="name" class="form-control" value="{{ $list['goods_name'] }}" id="exampleInputName" placeholder="goods name">
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputCate">商品分类</label>
                                    <select name="cate" class="form-control">
                                        <option value="{{ $list['category_id'] }}">{{ App\Category::find($list['category_id'])['name'] }}</option>
                                        @foreach($cate as $c)
                                            <option value="{{ $c['id'] }}">{{ $c['name'] }}</option>
                                        @endforeach
                                    </select>
                                </div>
                                {{--<div class="form-group">--}}
                                    {{--<label for="exampleInputName">商品标签</label>--}}
                                    {{--<select name="lable" class="form-control">--}}
                                        {{--<option value="{{ $list['lable'] }}">{{ App\Lable::find($list['lable'])['name'] }}</option>--}}
                                        {{--@foreach($lable as $l)--}}
                                            {{--<option value="{{ $l['id'] }}">{{ $l['name'] }}</option>--}}
                                        {{--@endforeach--}}
                                    {{--</select>--}}
                                {{--</div>--}}
                                <div class="form-group">
                                    <label for="exampleInputName">商品描述</label>
                                    <textarea rows="4" style="width: 100%" name="intro"  value="">{{ $list['goods_introduce'] }}</textarea>
                                    {{--<input type="text" name="intro" value="{{ $list['goods_introduce'] }}" class="form-control" id="exampleInputName" placeholder="goods intro">--}}
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputName">商品价格</label>
                                    <input type="text" name="price" value="{{ $list['goods_price'] }}" class="form-control" id="exampleInputName" placeholder="goods price">
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputName">商品库存</label>
                                    <input type="text" name="invent" class="form-control" value="{{ $list['goods_inventory'] }}" id="exampleInputName" placeholder="goods invent">
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputName">商品详图</label>
                                    <input type="file" name="picture" onchange="PreviewImage(this)" class="form-control" id="exampleInputName">
                                    <div id="imgPreview" >
                                        <img src="/productImg/{{ $list['goods_picture'] }}" width="250" height="150" style="border: 1px dashed #ccc">
                                    </div>
                                    <script>
                                        function PreviewImage(imgFile)
                                        {
                                            var filextension=imgFile.value.substring(imgFile.value.lastIndexOf("."),imgFile.value.length);
                                            filextension=filextension.toLowerCase();
                                            if ((filextension!='.jpg')&&(filextension!='.gif')&&(filextension!='.jpeg')&&(filextension!='.png')&&(filextension!='.bmp'))
                                            {
                                                alert("对不起，系统仅支持标准格式的照片，请您调整格式后重新上传，谢谢 !");
                                                imgFile.focus();
                                            }
                                            else
                                            {
                                                var path;
                                                if(document.all)//IE
                                                {
                                                    imgFile.select();
                                                    path = document.selection.createRange().text;
                                                    document.getElementById("imgPreview").innerHTML="";
                                                    document.getElementById("imgPreview").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src=\"" + path + "\")";//使用滤镜效果
                                                }
                                                else//FF
                                                {
                                                    path=window.URL.createObjectURL(imgFile.files[0]);// FF 7.0以上
                                                    //path = imgFile.files[0].getAsDataURL();// FF 3.0
                                                    document.getElementById("imgPreview").innerHTML = "<img id='img1' width='250px' height='150px' src='"+path+"'/>";
                                                    //document.getElementById("img1").src = path;
                                                }
                                            }
                                        }
                                    </script>
                                </div>
                            </div>
                            <div class="box-footer">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </section>
    </div>
@stop